package hc.bre.deci.tree

import hc.bre.ComponentConfig
import hc.bre.cmn.RuleScriptBuilder
import hc.bre.cmn.RuleDefinition
import hc.bre.deci.action.ActionDefinition

@groovy.transform.CompileStatic
@groovy.transform.ToString(includeNames=true, includePackage = false)
class TreeDefinition extends RuleDefinition{
	public static final ComponentConfig _config ;
	static {
		_config = new ComponentConfig();
		_config.rtype = 'rule:deci:tree';
		_config.rname = '决策树';
		_config.builderClass = TreeBuilder;
		_config.resultStruct = new hc.bre.deci.tree.TreeResultStruct();
		_config.objectpage = '/rule/deci/treehome.htm?rpath=${rpath}';
		_config.description = '''通过一个树结构的细分过程，对每一个分支情景进行决策<br />''';
	}
	public static TreeDefinition create() {
		TreeDefinition ruleDef = new TreeDefinition();
		TreeBranchItem branch = new TreeBranchItem();
		branch.id= ++ruleDef.rmaxid ;
		branch.referId=0;
		branch.referName = '开始';
		branch.rpath = '';
		branch.rname = '';
		branch.valueMap = [:];

		ruleDef.root = branch;
		ruleDef.actionDefList =[];

		return ruleDef;
	}

	int actionmaxid;
	List<ActionDefinition> actionDefList;
	TreeBranchItem root ;

	//TODO SUPPORT PolicySetter
	
	@Override
	public TreeDefinition load(Map map) {
		super.load(map);
		this.actionmaxid = map['actionmaxid'] as Integer;
		this.actionDefList = hc.Util.loadList(map['actionDefList'], ActionDefinition.class);
		this.root = hc.Util.loadBean(map['root'], TreeBranchItem.class);

		return this;
	}
}
